<template>
  <div class="comment-reply">
    <!-- 导航栏 -->
    <van-nav-bar :title="comment.reply_count>0?`${comment.reply_count}条回复`:'暂无回复'">
      <van-icon
        slot="left"
        name="cross"
        @click="$emit('close')"
      />
    </van-nav-bar>
    <!-- /导航栏 -->
    <div class="scroll-warp">

      <!-- 当前评论项 -->
      <comment-item :comment="comment"></comment-item>
      <!-- /当前评论项 -->
      <!-- 评论的回复列表 -->
      <van-cell title="全部回复" />
      <comment-list :list="commentList" :source="comment.com_id" type="c"></comment-list>
      <!-- /评论的回复列表 -->
    </div>
    <!-- 底部 -->
    <div class="post-warp">
      <van-button class="post-btn" size="small" round @click="isPostShow = true">写评论</van-button>
    </div>
    <van-popup
      v-model="isPostShow"
      position="bottom"
    >
      <comment-post :target="comment.com_id" @post-success="onPostSuccess"></comment-post>
    </van-popup>
    <!-- /底部 -->
  </div>
</template>

<script>
import commentItem from '@/components/comment-item.vue'
import commentList from '@/components/comment-list.vue'
import commentPost from '@/components/comment-post.vue'
export default {
  name: 'CommentReply',
  components: { commentItem, commentList, commentPost },
  props: {
    comment: {
      type: Object,
      required: true
    }
  },
  data () {
    return {
      isPostShow: false,
      commentList: []
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
    onPostSuccess (data) {
      this.comment.reply_count++
      this.isPostShow = false
      this.commentList.unshift(data.new_obj)
    }
  }
}
</script>

<style scoped lang="less">
.comment-reply {
  .scroll-warp{
    position: fixed;
    top:46px;
    left: 0;
    right: 0;
    bottom: 44px;
    overflow-y: auto;
  }
  .post-warp {
    position: fixed;
    height: 44px;
    bottom: 0;
    right: 0;
    left: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #fff;
    border-top: 1px solid #d8d8d8;
    .post-btn{
      width: 60%;
    }
  }
}
</style>
